<template>
  <div class="birthday-picker"
       @click="show()"
       :style="getFatherStyle()">
    <div class="birthday-picker__span">
      <span :class="{'birthday-picker__span-selected': selectedValue.trim().length > 0 }"
    
            :style="getSeletedStyle()">{{showText}}</span>
    </div>
    <div class="birthday-picker__img"><img src="@image/date-right.png"></div>
    <picker :isVisible="isShow"
            :defaultValue="selectedValue"
            @operaDialog="operaDialog"></picker>
    <!-- :default-index="pickerDefaultIndex" -->
  </div>
</template>
<style lang="stylus" scoped>
.birthday-picker {
  width: 100%;
  height: 100%;
  // @include flex-h(space-between);
  align-items: center;

  .birthday-picker__img {
    width: 17px;
    height: 28px;
    display: flex;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .birthday-picker__span-selected {
    color: #2c2c2c;
  }

  .birthday-picker__span {
    display: flex;

    span {
      // margin-left: 9px;
      margin-right: 19.1px;
      font-size: 30px;
      text-align: center;
      color: #b2b2b8;
    }
  }
}
</style>
<script>

import picker from './picker-dialog'
export default {
  name: 'birthday-picker',
  mixins: [],
  data () {
    return { selectedValue: '', isShow: false, pickerData: [] }
  },
  components: {
    picker
  },
  props: {
    setText: {
      type: String,
      default: ''
    },
    list: {
      type: Array,
      default () {
        return []
      }
    },
    title: {
      type: String,
      default: ''
    },
    placeholder: {
      type: String,
      default: '请选择'
    },
    position: {
      type: String,
      default: 'left'
    },
    selectedStyle: {
      type: Object,
      default: function () {
        return { color: '#2c2c2c' }
      }
    }
  },
  mounted () {
    this.pickerData = [
      [
        {
          // 选项展示文案
          'text': '222',
          // 以下自定义字段
          'value': '4456'
        }
      ]
    ]
  },
  computed: {
    showText () {
      if (this.selectedValue.trim().length > 0) {
        return this.selectedValue
      } else if (this.setText.trim().length > 0) {
        this.selectedValue = this.setText
        return this.setText
      } else {
        return this.placeholder
      }
    }
  },
  watch: {},
  methods: {
    operaDialog (value) {
      if (value) {
        this.selectedValue = value
      }
      this.isShow = false
    },
    show () {
      // this.datePicker.show()
      this.isShow = true
    },
    getFatherStyle: function () {
      switch (this.position) {
        case 'left':
          return {
            display: 'flex',
            'justify-content': 'space-between',
            'flex-direction': 'row'
          }
        case 'right':
          return {
            display: 'flex',
            'justify-content': 'flex-end',
            'flex-direction': 'row'
          }
      }
    },
    getSeletedStyle: function () {
      if (this.selectedValue.trim().length > 0) {
        return this.selectedStyle
      }
    }
  }
}
</script>
